import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/elec_price_title_widget.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/energy_storeage_discharge_price/widgets/store_stage_price_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

///
/// @Description TODO
/// @Author liuer
/// @CreateTime 2024年03月26日 17:42
class ElectricityEnergyStoragePeriods extends StatelessWidget {
  final List<dynamic> stagePriceList;
  final Function() addCallBack;
  final Function(int index) deleteCallBack;
  final Function() dateCallBack;
  final Function() typeClickCallBack;
  final bool isCanEdit;
  const ElectricityEnergyStoragePeriods(
      this.stagePriceList, this.addCallBack, this.deleteCallBack,
      this.dateCallBack,this.typeClickCallBack,
      {this.isCanEdit = true,Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      // height: stagePriceList.length * 145 + 58 + 50,
        child: Column(
          children: [
            // ElecPriceTitleWidget(ResKey.siteSettingElectricityStagePrice.tr),
            ListView.builder(
              padding: EdgeInsets.zero,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (BuildContext context, int index) =>
                  StoreStagePriceWidget(
                    context,
                    '${ResKey.siteSettingElectricityTimeStage.tr}${index + 1}',
                    stagePriceList[index]['intervalStartTime'],
                    stagePriceList[index]['intervalEndTime'],
                    stagePriceList[index]['electricityFees'].toString(),
                    stagePriceList[index]['elecType'].toString(),
                        (startDateTime, endDateTime) {
                      if(startDateTime == '23:59'){
                        startDateTime = '24:00';
                      }
                      if(endDateTime == '23:59'){
                        endDateTime = '24:00';
                      }
                      var map = stagePriceList[index];
                      map['intervalStartTime'] = startDateTime;
                      map['intervalEndTime'] = endDateTime;
                      stagePriceList[index] = map;
                      dateCallBack();
                    },
                        () {
                      deleteCallBack(index);
                    },
                        (str) {
                      var map = stagePriceList[index];
                      map['electricityFees'] = str;
                      stagePriceList[index] = map;
                      typeClickCallBack();
                    },(str){
                    var map = stagePriceList[index];
                    map['serviceFees'] = str;
                    stagePriceList[index] = map;
                    typeClickCallBack();
                  },isDelete: true,),
              itemCount: stagePriceList.length,
            ),
            Container(
              height: 0.5,
              color: Colour.dividerColor,
              margin: EdgeInsets.only(left: 16.w, right: 16.w),
            ),
            Visibility(
                visible: isCanEdit,
                child: GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      addCallBack();
                    },
                    child: SizedBox(
                      height: 49,
                      child: Row(
                        children: [
                          Container(
                            padding: EdgeInsets.only(left: 16, right: 16),
                            child: Image.asset(
                              'assets/images/site_elec_price_add.png',
                              height: 18,
                              width: 18,
                            ),
                          ),
                          Text(
                            ResKey.siteSettingElectricityAddStage.tr,
                            style: ytTextStyle(
                                fontWeight: FontWeight.normal,
                                color: Colour.primaryColor,
                                fontSize: 14),
                          ),
                        ],
                      ),
                    )))
          ],
        ));
  }
}
